package com.shengyin.ec.model.dao.account;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.shengyin.ec.model.dao.BaseDaoImpl;
import com.shengyin.ec.model.entity.Receiver;


@Repository("receiverDao")
public class ReceiverDaoImpl extends BaseDaoImpl<Receiver> implements ReceiverDao {

	@Override
	public List<Receiver> getReceiverListById(long id){
		List<Receiver> receiverList = (List<Receiver>)super.find("from Receiver r where r.userId='"+id+"'");
		return receiverList;
	}

	@Override
	public void setDefaultReceiver(long userId, long receiverId) {
		List<Receiver> list = this.getReceiverListById(userId);
		for(Receiver receiver : list){
			if(receiverId==receiver.getId()){
				receiver.setIsDefaultAddress("1");
			}else{
				receiver.setIsDefaultAddress("0");
			}
		}
	}
}